package cn.bonoon.kernel.support.models;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.bonoon.kernel.util.StringHelper;
import cn.bonoon.kernel.util.StringHelper.DataItem;

public class PropertyEditor implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 7822426231521816225L;
	public static final String[] optionNames;
	private static final Object[] editors;
	static{
		PropertyEditor checkbox = new PropertyEditor("checkbox");
		checkbox.options.put("on", true);
		checkbox.options.put("off", false);
		optionNames = new String[]{"文本", "数值", "日期", "布尔值", "选择项", "大文本"};
		editors = new Object[]{"text", "numberbox", "datebox", checkbox, "combobox", "textarea"};
	}
	public static final Object editor(int i, String v){
		if(i == 4){
			List<DataItem> items = StringHelper.toData(v);
			PropertyEditor combobox = new PropertyEditor("combobox");
			combobox.options.put("data", items);
			return combobox;
		}
		return editors[i];
	}
	
	private final String type;
	private final Map<String, Object> options;
	
	public PropertyEditor(String type){
		this.type = type;
		this.options = new HashMap<String, Object>();
	}

	public String getType() {
		return type;
	}

	public Object getOptions() {
		return options;
	}
}
